<template>
  <el-dialog :title="title" :visible.sync="open" width="960px" @close="cancel" append-to-body v-drag-fullscreen>
    <el-row :gutter="10" class="mb8">
      <el-col :span="24">
        <el-form :inline="true" :model="queryParams" ref="queryForm" size="small" label-width="0"
                 class="demo-form-inline" style="height: 40px;float: right;">
          <el-form-item prop="costNo">
            <el-input
              v-model="queryParams.costNo"
              placeholder="费用单号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item style="width: 100px;" prop="status">
            <el-select v-model="queryParams.status" placeholder="费用状态" clearable size="small">
              <el-option
                v-for="dict in dict.charge_status"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="receivableTime"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="应收日期开始"
              end-placeholder="应收日期结束">
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="success" size="mini" :icon="queryParams.params.searchQuery?'el-icon-loading':''"
                       @click="$refs.queryRef.show()">高级查询
            </el-button>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="ruleCostList">
      <el-table-column label="单据号" align="left" prop="costNo" width="120"/>
      <el-table-column label="房屋名称" align="left" width="120" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{scope.row.roomName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户" align="left" prop="ownerName" width="100"/>
      <el-table-column label="收费标准" align="left" prop="normNames" width="120"/>
      <el-table-column label="费用期间" align="center" prop="receivableTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receivableTime, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计费开始日期" align="center" prop="beginTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.beginTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计费结束日期" align="center" prop="finishTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单价" align="center" prop="prices" width="60"/>
      <el-table-column label="应收金额" align="center" prop="receivableMoney" width="100"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">返 回</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {listRuleCost} from "@/api/payfee/ruleCost";
  import {listMixin} from "@/utils/mixins/listMixin";

  export default {
    name: "RuleCost",
    mixins: [listMixin],
    dicts: ['charge_status'],
    data() {
      return {
        open: false,
        title: "费用账单列表",
        ruleCostList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          costNo: null,
          status: null,
          batcheNo: null,
          params: {}
        },
        receivableTime: [], //应收日期
        queryColumns: [
          {title: '费用单号', key: 'cost_no', typeCode: '', type: 'input', value: ''},
          {title: '客户名称', key: 'owner_name', type: 'input', value: '', alias: 'tor'},
          {title: '计费开始时间', key: 'begin_time', type: 'date', value: ''},
          {title: '计费结束时间', key: 'finish_time', type: 'date', value: ''},
        ],
        batcheNo: null,
      };
    },
    created() {

    },
    methods: {
      show(options) {
        this.batcheNo = options.batcheNo
        this.open = true
        this.getList()
      },
      /** 查询结账记录列表 */
      getList() {
        this.loading = true;
        this.queryParams.batcheNo = this.batcheNo || -1
        let queryParams = this.addDateRange(this.queryParams, this.receivableTime, "receivableTime")
        listRuleCost(queryParams).then(res => {
          this.ruleCostList = res.rows
          this.total = res.total
          this.loading = false;
        });
      },
      cancel() {
        this.open = false
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
